bcr: Change handling of DESCRIPTION lines. Regenerate reference files.
authoroliskoli <oliskoli>
Sun, 15 Apr 2007 18:59:06 +0000 (18:59 +0000)
committeroliskoli <oliskoli>
Sun, 15 Apr 2007 18:59:06 +0000 (18:59 +0000)
bcr.c
reference/route/bcr-sample.bcr
reference/route/bcr-sample.gpx
reference/route/bcr-sample2.bcr

diff --git a/bcr.c b/bcr.c
index d212f3e3dc1f3e884cd73968a0a715df23230718..4d0ad1318ac92c63b76942e4f2e723a3c94a6683 100644 (file)
--- a/bcr.c
+++ b/bcr.c
     2006/01/22: reader simplified with inifile library
     2007/01/30: new option prefer_shortnames
                don't check global_opts.objective
+    2007/04&14: new handling of DESCRIPTION lines
 */
 
 #include "defs.h"
+#include "csv_util.h"
 #include "garmin_tables.h"
 #include <ctype.h>
 #include <stdio.h>
@@ -39,6 +41,9 @@
 #undef BCR_DEBUG
     
 #define R_EARTH                6371000         /* radius of our big blue ball */
+#define BCR_DEF_ICON           "Standort"
+#define BCR_DEF_MPS_ICON       "Waypoint"
+#define BCR_UNKNOWN            (double) 999999999
 
 /*  
     6371014 would be a better value when converting to f.e. to mapsoure,
@@ -71,13 +76,101 @@ arglist_t bcr_args[] = {
        ARG_TERMINATOR
 };
 
+typedef struct {
+       char *bcr_name;
+       char *mps_name;
+       char *symbol_DE;
+       int  warned;
+} bcr_icon_mapping_t;
+
+static
+bcr_icon_mapping_t bcr_icon_mapping[] = {
+       { BCR_DEF_ICON,         BCR_DEF_MPS_ICON,       BCR_DEF_ICON },
+       { "",                   BCR_DEF_MPS_ICON,       "Eigene Adressen" },
+       { "AdrMon alpen",       "Summit",               "Pass-Strassen" },
+       { "AdrMon bauern",      NULL,                   "Bauern- und Biohoefe" },
+       { "AdrMon cmpngs",      "Campground",           "Campingplaetzte" },
+       { "AdrMon p_aeu",       "Scenic Area",          "Sehenswertes" },
+       { "AdrMon p_beu",       "Gas Station",          "Tanken" },
+       { "AdrMon p_deu",       "Parking Area",         "Parken" },
+       { "AdrMon p_feu",       "Restaurant",           "Gastro" },
+       { "AdrMon p_geu",       "Museum",               "Freizeit" },
+       { "AdrMon p_heu",       "Gas Station",          "Tankstellen" },
+       { "AdrMon p_keu",       NULL,                   "Faehrverbindungen" },
+       { "AdrMon p_leu",       NULL,                   "Grenzuebergaenge" },
+       { "AdrMon p_teu",       NULL,                   "Wein- und Sektgueter" },
+       { "AdrMon RUINEN",      "Ghost Town",           "Burgen und Schloesser" },
+       { "AdrMon NFHAUS",      "Residence",            "Naturfreundehaeuser" },
+       { "AdrMon racing",      "Bike Trail",           "Rennstrecken" },
+       { "AdrMon TNKRST",      "Bar",                  "Tankraststaetten" },
+       { "AdrMon tpclub",      "Contact, Biker",       "Motorrad-Clubs" },
+       { "AdrMon tpequ",       NULL,                   "Motorrad-Equipment" },
+       { "AdrMon tphot",       "Hotel",                "Motorrad-Hotels" },
+       { "AdrMon tpmh",        NULL,                   "Motorradhaendler" },
+       { "AdrMon tpss",        "Restricted Area",      "Sperrungen" },
+       { "AdrMon tpsw",        "Scenic Area",          "Sehenswertes" },
+       { "AdrMon tptref",      NULL,                   "Treffpunkte" },
+       { "AdrMon VORTE",       "Information",          "Ortsinformationen" },
+       { "AdrMon WEBCAM",      NULL,                   "WebCam-Standorte" },
+       { "AdrMon youthh",      NULL,                   "Jugendherbergen" },
+       { "Town",               "City (Small)",         "Orte" },
+       { NULL,                 NULL,                   NULL, 0 }
+};
+
+static void
+bcr_handle_icon_str(const char *str, waypoint *wpt)
+{
+       bcr_icon_mapping_t *m;
+       
+       wpt->icon_descr = BCR_DEF_MPS_ICON;
+       
+       for (m = bcr_icon_mapping; (m->bcr_name); m++) {
+               if (case_ignore_strcmp(str, m->bcr_name) == 0) {
+                       int nr;
+                       
+                       if (m->symbol_DE == NULL) {
+                               if (! m->warned) {
+                                       m->warned = 1;
+                                       warning(MYNAME ": Unknown icon \"%s\" found. Please report.\n", str);
+                               }
+                               return;
+                       }
+                       wpt->description = xstrdup(m->symbol_DE);
+                       if (m->mps_name != NULL) {
+                               nr = gt_find_icon_number_from_desc(m->mps_name, MAPSOURCE);
+                               wpt->icon_descr = gt_find_desc_from_icon_number(nr, MAPSOURCE, NULL);
+                       }
+                       return;
+               }
+       }
+}
+
+static char *
+get_bcr_icon_from_icon_descr(const char *icon_descr)
+{
+       char *result = BCR_DEF_ICON;
+       
+       if (icon_descr) {
+               bcr_icon_mapping_t *m;
+               
+               for (m = bcr_icon_mapping; (m->bcr_name); m++) {
+                       if (! m->mps_name) continue;
+                       if (case_ignore_strcmp(icon_descr, m->mps_name) == 0) {
+                               result = m->bcr_name;
+                               break;
+                       }
+               }
+       }
+       return result;
+}
+
 static void
 bcr_init_radius(void)
 {
        if (radius_opt != NULL)                         /* preinitialize the earth radius */
        {
                radius = atof(radius_opt);
-               if (radius < 0)
+               if (radius <= 0)
                        fatal(MYNAME ": Sorry, the radius should be greater than zero!\n");
        }
        else
@@ -162,7 +255,6 @@ bcr_data_read(void)
                char station[32];
                char *str;
                int mlat, mlon;         /* mercator data */
-               double xalt;
                waypoint *wpt;
                
                snprintf(station, sizeof(station), "STATION%d", index);
@@ -184,23 +276,26 @@ bcr_data_read(void)
                        if (cx == NULL)
                                fatal(MYNAME ": structure error at %s (Client)!\n", station);
                        *cx++ = '\0';
+                       bcr_handle_icon_str(str, wpt);
+               }
+               
+               if (NULL != (str = inifile_readstr(ini, "description", station))) {
+                       char *c;
                        
-                       xalt = atof(cx);
-                       if (xalt != 999999999) {
-                               wpt->altitude = FEET_TO_METERS(xalt);
+                       c = strchr(str, ',');
+                       if (c != NULL) *c = '\0';
+                       if (*str) wpt->notes = xstrdup(str);
+                       if ((str = c)) {
+                               str++;
+                               c = strchr(str, ',');
+                               if (c != NULL) *c = '\0';
+                               if (*str) {
+                                       xfree(wpt->shortname);
+                                       wpt->shortname = xstrdup(str);
+                               }
                        }
-                       
-                       if (case_ignore_strcmp(str, "Standort") == 0)
-                           wpt->icon_descr = gt_find_desc_from_icon_number(18, MAPSOURCE, NULL);
-                       else if (case_ignore_strcmp(str, "Town") == 0)
-                           wpt->icon_descr = gt_find_desc_from_icon_number(69, MAPSOURCE, NULL);
-                       else
-                           warning(MYNAME ": Unknown icon \"%s\" found. Please report.\n", str);
                }
                
-               if (NULL != (str = inifile_readstr(ini, "description", station)))
-                       wpt->description = xstrdup(str);
-               
                route_add_wpt(route, wpt);
        }
        bcr_create_waypts_from_route(route);
@@ -257,9 +352,8 @@ bcr_route_header(const route_head *route)
 {
        queue *elem, *tmp;
        waypoint *wpt;
-       char *c;
-       int i, icon, north, east, nmin, nmax, emin, emax;
-       char buff[128], symbol[32];
+       char *sout;
+       int i, north, east, nmin, nmax, emin, emax;
        
        curr_rte_num++;
        if (curr_rte_num != target_rte_num) return;     
@@ -267,31 +361,28 @@ bcr_route_header(const route_head *route)
        bcr_write_line(fout, "[CLIENT]", NULL, NULL);                   /* client section */
        bcr_write_line(fout, "REQUEST", NULL, "TRUE");
        
-       c = route->rte_name;
-       if (rtename_opt != 0) c = rtename_opt;
-       if (c != NULL)
-               bcr_write_line(fout, "ROUTENAME", NULL, c);
+       sout = route->rte_name;
+       if (rtename_opt != 0) sout = rtename_opt;
+       if (sout != NULL)
+               bcr_write_line(fout, "ROUTENAME", NULL, sout);
        else
                bcr_write_line(fout, "ROUTENAME", NULL, "Route");
 
-       bcr_write_line(fout, "DESCRIPTIONLINES", NULL, "1");
-       bcr_write_line(fout, "DESCRIPTION1", NULL, "");
+       bcr_write_line(fout, "DESCRIPTIONLINES", NULL, "0");
        
        i = 0;
-
        QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) 
        {
+               char *icon;
+               waypoint *wpt = (waypoint *) elem;
+
                i++;
-               wpt = (waypoint *) elem;
                
-               strncpy(symbol, "Standort", sizeof(symbol));
-               if (wpt->icon_descr != 0) {
-                       icon = gt_find_icon_number_from_desc(wpt->icon_descr, MAPSOURCE);
-                       if ((icon >= 69) && (icon <= 72))
-                               strncpy(symbol, "Town", sizeof(symbol));
-               }
-               snprintf(buff, sizeof(buff), "%s,%s", symbol, "999999999");
-               bcr_write_line(fout, "STATION", &i, buff);
+               icon = get_bcr_icon_from_icon_descr(wpt->icon_descr);
+
+               xasprintf(&sout, "%s,%.f", icon, BCR_UNKNOWN);
+               bcr_write_line(fout, "STATION", &i, sout);
+               xfree(sout);
        }
            
        bcr_write_line(fout, "[COORDINATES]", NULL, NULL);              /* coords section */
@@ -312,8 +403,9 @@ bcr_route_header(const route_head *route)
                if (north < nmin) nmin = north;
                if (east < emin) emin = east;
                
-               snprintf(buff, sizeof(buff), "%d,%d", east, north);
-               bcr_write_line(fout, "STATION", &i, buff);
+               xasprintf(&sout, "%d,%d", east, north);
+               bcr_write_line(fout, "STATION", &i, sout);
+               xfree(sout);
        }
        
        bcr_write_line(fout, "[DESCRIPTION]", NULL, NULL);              /* descr. section */
@@ -321,18 +413,37 @@ bcr_route_header(const route_head *route)
        i = 0;
        QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) 
        {
+               char *s1, *s2, *sout;
+               
                i++;
                wpt = (waypoint *) elem;
-               c = wpt->description;
-               if (prefer_shortnames_opt || (c == NULL) || (*c == '\0'))
-                       c = wpt->shortname;
-               bcr_write_line(fout, "STATION", &i, c);
+               s1 = wpt->notes;
+               if (s1 == NULL) s1 = wpt->description;
+               
+               if (prefer_shortnames_opt || (s1 == NULL) || (*s1 == '\0')) {
+                       s2 = s1;
+                       s1 = wpt->shortname;
+               }
+               else s2 = wpt->shortname;
+               
+               if (s1 == NULL) s1 = xstrdup("");
+               else s1 = csv_stringclean(s1, ",\t\r\n");
+               if (s2 == NULL) s2 = xstrdup("");
+               else s2 = csv_stringclean(s2, ",\t\r\n");
+               
+               xasprintf(&sout, "%s,%s,,0", s1, s2);
+               bcr_write_line(fout, "STATION", &i, sout);
+               
+               xfree(s1);
+               xfree(s2);
+               xfree(sout);
        }
        
        bcr_write_line(fout, "[ROUTE]", NULL, NULL);                    /* route section */
 
-       snprintf(buff, sizeof(buff), "%d,%d,%d,%d", emin, nmax, emax, nmin);
-       bcr_write_line(fout, "ROUTERECT", NULL, buff);
+       xasprintf(&sout, "%d,%d,%d,%d", emin, nmax, emax, nmin);
+       bcr_write_line(fout, "ROUTERECT", NULL, sout);
+       xfree(sout);
        
 }
 
index 72a9ec49de6fe5d4fc9e9b6db4264cb0ddeb5dcd..3cc8f0bb6e5bc0e22f28bf649194c947e13eca98 100644 (file)
@@ -3,15 +3,15 @@ REQUEST=TRUE
 ROUTENAME=DE_Plauen-Leipzig
 DESCRIPTIONLINES=1
 DESCRIPTION1=
-STATION1=Standort,999999999
-STATION2=Standort,999999999
+STATION1=Town,999999999
+STATION2=AdrMon VORTE,999999999
 STATION3=Standort,999999999
 STATION4=Standort,999999999
 STATION5=Standort,999999999
 STATION6=Standort,999999999
 STATION7=Standort,999999999
 STATION8=Standort,999999999
-STATION9=Standort,999999999
+STATION9=Town,999999999
 [COORDINATES]
 STATION1=1346067,6524736
 STATION2=1346265,6524980
index ea279c36edf6436af93cc7fd08c7c45bed53a6f6..2fd339028891b75dd959a9755969332555d00066 100644 (file)
@@ -8,114 +8,114 @@ xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/
 <time>1970-01-01T00:00:00Z</time>
 <bounds minlat="50.492706401" minlon="12.105471361" maxlat="51.314684001" maxlon="12.492485421"/>
 <wpt lat="50.492706401" lon="12.105471361">
-  <name>STATION1</name>
-  <cmt>bei D 08527,Neundorf,,0,</cmt>
-  <desc>bei D 08527,Neundorf,,0,</desc>
-  <sym>Waypoint</sym>
+  <name>Neundorf</name>
+  <cmt>Orte</cmt>
+  <desc>bei D 08527</desc>
+  <sym>City (Small)</sym>
 </wpt>
 <wpt lat="50.494102371" lon="12.107252018">
-  <name>STATION2</name>
-  <cmt>bei D 08523,Plauen/Possig,,0,</cmt>
-  <desc>bei D 08523,Plauen/Possig,,0,</desc>
-  <sym>Waypoint</sym>
+  <name>Plauen/Possig</name>
+  <cmt>Ortsinformationen</cmt>
+  <desc>bei D 08523</desc>
+  <sym>Information</sym>
 </wpt>
 <wpt lat="50.497986840" lon="12.105885049">
-  <name>STATION3</name>
-  <cmt>bei D 08523,Plauen/Westend,,0,</cmt>
-  <desc>bei D 08523,Plauen/Westend,,0,</desc>
+  <name>Plauen/Westend</name>
+  <cmt>Standort</cmt>
+  <desc>bei D 08523</desc>
   <sym>Waypoint</sym>
 </wpt>
 <wpt lat="50.688914683" lon="12.327792655">
-  <name>STATION4</name>
-  <cmt>bei D 08427,Fraureuth/Beiersdorf,,0,</cmt>
-  <desc>bei D 08427,Fraureuth/Beiersdorf,,0,</desc>
+  <name>Fraureuth/Beiersdorf</name>
+  <cmt>Standort</cmt>
+  <desc>bei D 08427</desc>
   <sym>Waypoint</sym>
 </wpt>
 <wpt lat="50.864403822" lon="12.429074255">
-  <name>STATION5</name>
-  <cmt>bei D 04639,Ponitz/Merlach,,0,</cmt>
-  <desc>bei D 04639,Ponitz/Merlach,,0,</desc>
+  <name>Ponitz/Merlach</name>
+  <cmt>Standort</cmt>
+  <desc>bei D 04639</desc>
   <sym>Waypoint</sym>
 </wpt>
 <wpt lat="50.971321599" lon="12.452645474">
-  <name>STATION6</name>
-  <cmt>bei D 04600,Altenburg/Paditz,,0,</cmt>
-  <desc>bei D 04600,Altenburg/Paditz,,0,</desc>
+  <name>Altenburg/Paditz</name>
+  <cmt>Standort</cmt>
+  <desc>bei D 04600</desc>
   <sym>Waypoint</sym>
 </wpt>
 <wpt lat="51.171165953" lon="12.492485421">
-  <name>STATION7</name>
-  <cmt>bei D 04552,Borna/Gestewitz,,0,</cmt>
-  <desc>bei D 04552,Borna/Gestewitz,,0,</desc>
+  <name>Borna/Gestewitz</name>
+  <cmt>Standort</cmt>
+  <desc>bei D 04552</desc>
   <sym>Waypoint</sym>
 </wpt>
 <wpt lat="51.238200898" lon="12.388856592">
-  <name>STATION8</name>
-  <cmt>bei D 04564,Boehlen/Grossdeuben,,0,</cmt>
-  <desc>bei D 04564,Boehlen/Grossdeuben,,0,</desc>
+  <name>Boehlen/Grossdeuben</name>
+  <cmt>Standort</cmt>
+  <desc>bei D 04564</desc>
   <sym>Waypoint</sym>
 </wpt>
 <wpt lat="51.314684001" lon="12.409118308">
-  <name>STATION9</name>
-  <cmt>bei D 04317,Leipzig/Thonberg,,0,</cmt>
-  <desc>bei D 04317,Leipzig/Thonberg,,0,</desc>
-  <sym>Waypoint</sym>
+  <name>Leipzig/Thonberg</name>
+  <cmt>Orte</cmt>
+  <desc>bei D 04317</desc>
+  <sym>City (Small)</sym>
 </wpt>
 <rte>
   <name>DE_Plauen-Leipzig</name>
   <rtept lat="50.492706401" lon="12.105471361">
-    <name>STATION1</name>
-    <cmt>bei D 08527,Neundorf,,0,</cmt>
-    <desc>bei D 08527,Neundorf,,0,</desc>
-    <sym>Waypoint</sym>
+    <name>Neundorf</name>
+    <cmt>Orte</cmt>
+    <desc>bei D 08527</desc>
+    <sym>City (Small)</sym>
   </rtept>
   <rtept lat="50.494102371" lon="12.107252018">
-    <name>STATION2</name>
-    <cmt>bei D 08523,Plauen/Possig,,0,</cmt>
-    <desc>bei D 08523,Plauen/Possig,,0,</desc>
-    <sym>Waypoint</sym>
+    <name>Plauen/Possig</name>
+    <cmt>Ortsinformationen</cmt>
+    <desc>bei D 08523</desc>
+    <sym>Information</sym>
   </rtept>
   <rtept lat="50.497986840" lon="12.105885049">
-    <name>STATION3</name>
-    <cmt>bei D 08523,Plauen/Westend,,0,</cmt>
-    <desc>bei D 08523,Plauen/Westend,,0,</desc>
+    <name>Plauen/Westend</name>
+    <cmt>Standort</cmt>
+    <desc>bei D 08523</desc>
     <sym>Waypoint</sym>
   </rtept>
   <rtept lat="50.688914683" lon="12.327792655">
-    <name>STATION4</name>
-    <cmt>bei D 08427,Fraureuth/Beiersdorf,,0,</cmt>
-    <desc>bei D 08427,Fraureuth/Beiersdorf,,0,</desc>
+    <name>Fraureuth/Beiersdorf</name>
+    <cmt>Standort</cmt>
+    <desc>bei D 08427</desc>
     <sym>Waypoint</sym>
   </rtept>
   <rtept lat="50.864403822" lon="12.429074255">
-    <name>STATION5</name>
-    <cmt>bei D 04639,Ponitz/Merlach,,0,</cmt>
-    <desc>bei D 04639,Ponitz/Merlach,,0,</desc>
+    <name>Ponitz/Merlach</name>
+    <cmt>Standort</cmt>
+    <desc>bei D 04639</desc>
     <sym>Waypoint</sym>
   </rtept>
   <rtept lat="50.971321599" lon="12.452645474">
-    <name>STATION6</name>
-    <cmt>bei D 04600,Altenburg/Paditz,,0,</cmt>
-    <desc>bei D 04600,Altenburg/Paditz,,0,</desc>
+    <name>Altenburg/Paditz</name>
+    <cmt>Standort</cmt>
+    <desc>bei D 04600</desc>
     <sym>Waypoint</sym>
   </rtept>
   <rtept lat="51.171165953" lon="12.492485421">
-    <name>STATION7</name>
-    <cmt>bei D 04552,Borna/Gestewitz,,0,</cmt>
-    <desc>bei D 04552,Borna/Gestewitz,,0,</desc>
+    <name>Borna/Gestewitz</name>
+    <cmt>Standort</cmt>
+    <desc>bei D 04552</desc>
     <sym>Waypoint</sym>
   </rtept>
   <rtept lat="51.238200898" lon="12.388856592">
-    <name>STATION8</name>
-    <cmt>bei D 04564,Boehlen/Grossdeuben,,0,</cmt>
-    <desc>bei D 04564,Boehlen/Grossdeuben,,0,</desc>
+    <name>Boehlen/Grossdeuben</name>
+    <cmt>Standort</cmt>
+    <desc>bei D 04564</desc>
     <sym>Waypoint</sym>
   </rtept>
   <rtept lat="51.314684001" lon="12.409118308">
-    <name>STATION9</name>
-    <cmt>bei D 04317,Leipzig/Thonberg,,0,</cmt>
-    <desc>bei D 04317,Leipzig/Thonberg,,0,</desc>
-    <sym>Waypoint</sym>
+    <name>Leipzig/Thonberg</name>
+    <cmt>Orte</cmt>
+    <desc>bei D 04317</desc>
+    <sym>City (Small)</sym>
   </rtept>
 </rte>
 </gpx>
index bc84a3e758261ac1df373bcaad44c049c43f94ce..a630c391660cb06eb2eb3d14a77e677c1bff6b31 100644 (file)
@@ -1,17 +1,16 @@
 [CLIENT]\r
 REQUEST=TRUE\r
 ROUTENAME=DE_Plauen-Leipzig\r
-DESCRIPTIONLINES=1\r
-DESCRIPTION1=\r
-STATION1=Standort,999999999\r
-STATION2=Standort,999999999\r
+DESCRIPTIONLINES=0\r
+STATION1=Town,999999999\r
+STATION2=AdrMon VORTE,999999999\r
 STATION3=Standort,999999999\r
 STATION4=Standort,999999999\r
 STATION5=Standort,999999999\r
 STATION6=Standort,999999999\r
 STATION7=Standort,999999999\r
 STATION8=Standort,999999999\r
-STATION9=Standort,999999999\r
+STATION9=Town,999999999\r
 [COORDINATES]\r
 STATION1=1346067,6524736\r
 STATION2=1346265,6524980\r
@@ -23,14 +22,14 @@ STATION7=1389101,6644184
 STATION8=1377578,6656081\r
 STATION9=1379831,6669676\r
 [DESCRIPTION]\r
-STATION1=bei D 08527,Neundorf,,0,\r
-STATION2=bei D 08523,Plauen/Possig,,0,\r
-STATION3=bei D 08523,Plauen/Westend,,0,\r
-STATION4=bei D 08427,Fraureuth/Beiersdorf,,0,\r
-STATION5=bei D 04639,Ponitz/Merlach,,0,\r
-STATION6=bei D 04600,Altenburg/Paditz,,0,\r
-STATION7=bei D 04552,Borna/Gestewitz,,0,\r
-STATION8=bei D 04564,Boehlen/Grossdeuben,,0,\r
-STATION9=bei D 04317,Leipzig/Thonberg,,0,\r
+STATION1=bei D 08527,Neundorf,,0\r
+STATION2=bei D 08523,Plauen/Possig,,0\r
+STATION3=bei D 08523,Plauen/Westend,,0\r
+STATION4=bei D 08427,Fraureuth/Beiersdorf,,0\r
+STATION5=bei D 04639,Ponitz/Merlach,,0\r
+STATION6=bei D 04600,Altenburg/Paditz,,0\r
+STATION7=bei D 04552,Borna/Gestewitz,,0\r
+STATION8=bei D 04564,Boehlen/Grossdeuben,,0\r
+STATION9=bei D 04317,Leipzig/Thonberg,,0\r
 [ROUTE]\r
 ROUTERECT=1346067,6669676,1389101,6524736\r